//
//  UneedGet2Api.m
//  uneed
//
//  Created by apple on 4/9/12.
//  Copyright 2012 __MyCompanyName__. All rights reserved.
//

#import "UneedGet2Api.h"
#import "ApiHelper.h"
#import "JSONKit.h"


@implementation UneedGet2Api

+ (NSArray *)getShopListsWithLat:(float)map_lat withLng:(float)map_lng {
	NSString *jsonstr =	[[NSString alloc] initWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@?act=item_list&catid=1",M_API]] encoding:NSUTF8StringEncoding error:nil];
	NSMutableDictionary *jsondic = [jsonstr objectFromJSONString];
	NSNumber *errCode = [jsondic objectForKey:@"errCode"];
	if ([errCode intValue]==0) {
		NSArray *json_ret = [jsondic objectForKey:@"errMessage"];
		return json_ret;
	}
	return nil;
}

+ (void)getShopListsWithLat:(float)map_lat withLng:(float)map_lng withPage:(int)thePage withDelegate:(id)theDelegate withIndex:(int)theIndex {
	ApiHelper  * apiHlp =[[ ApiHelper  alloc] initWithUrl:[NSString stringWithFormat:@"%@?act=item_list&catid=1&lat=%f&lng=%f&page=%d",M_API,map_lat,map_lng,thePage]
//	ApiHelper  * apiHlp =[[ ApiHelper  alloc] initWithUrl:[NSString stringWithFormat:@"%@?act=item_list&catid=1&page=%d",M_API,thePage]

												 postData:NULL
												 delegate: theDelegate
												withIndex:theIndex
										  onErrorCallback:@selector(errorCallback:)
									  onCompletedCallback:@selector(completedCallback:)];
	[apiHlp release]; 
	
}

+ (void)getCategorys:(id)theDelegate withIndex:(int)theIndex{
	ApiHelper  * apiHlp =[[ ApiHelper  alloc] initWithUrl:[NSString stringWithFormat:@"%@category.php",M_CACHE]
												 postData:NULL
												 delegate: theDelegate
												withIndex:theIndex
										  onErrorCallback:@selector(errorCallback:)
									  onCompletedCallback:@selector(completedCallback:)];
	[apiHlp release]; 
}

+ (void)getAreas:(id)theDelegate withIndex:(int)theIndex{
	ApiHelper  * apiHlp =[[ ApiHelper  alloc] initWithUrl:[NSString stringWithFormat:@"%@area.php",M_CACHE]
												 postData:NULL
												 delegate: theDelegate
												withIndex:theIndex
										  onErrorCallback:@selector(errorCallback:)
									  onCompletedCallback:@selector(completedCallback:)];
	[apiHlp release]; 
}

+ (void)loging:(NSString *)username withPassword:(NSString *)password withDelegate:(id)theDelegate withIndex:(int)theIndex {
	NSDictionary  * loginData=[NSDictionary  dictionaryWithObjectsAndKeys: 
							   username,@"username",
							   password,@"password",
							   @"yes",@"onsubmit",
							   nil];
	
	
	ApiHelper  * apiHlp =[[ ApiHelper  alloc] initWithUrl:[NSString stringWithFormat:@"%@?act=user&op=ulogin",M_API]
												 postData: loginData
												 delegate: theDelegate
												withIndex:theIndex
										  onErrorCallback:@selector(errorCallback:)
									  onCompletedCallback:@selector(completedCallback:)];
	[apiHlp release]; 
	
}



@end
